 %{
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#define YYSTYPE double

int yylex();
extern int yyparse();
FILE* yyin;
void yyerror(const char* s);
 %}

%token ADD SUB MUL DIV LKO RKO
%token NUMBER   
%left LKO
%left ADD SUB
%left MUL DIV
%right UMINUS
%right RKO

 %%


 lines : lines expr ';' {printf("%f\n",$2);}
       |  lines ';'
       |
       ;

 expr : expr ADD expr {$$=$1+$3;}
      |  expr SUB expr {$$=$1-$3;}
      |  expr MUL expr {$$=$1*$3;}
      |  expr DIV expr {$$=$1/$3;}
      | LKO expr RKO { $$=$2; }
      | SUB expr %prec UMINUS {$$=-$2;}
      | NUMBER { $$=$1; }
       ;

 %%

 // programs section

 int yylex()
 {
 // place your token retrieving code here
 int t ;
 while (1) {
 t = getchar ();
 if (t==' '||t=='\t'||t=='\n'){
 //do nothing
 }
 else if(isdigit (t)) {
 yylval = 0;
 while ( isdigit (t)) {
   yylval=yylval*10.0+t-'0';
 t = getchar ();
 }
 ungetc(t , stdin );
 return NUMBER;
 }
 else {
    switch(t)
     { 
      case '+':
          return ADD;
      case '-':
          return SUB;
       case '*':
          return MUL;
       case '/':
          return DIV;
      default:
            return t;
    }
 
 }
}
}
int main(void)
{
yyin = stdin ;
 do {
 yyparse();
 } while (! feof (yyin));
 return 0;
 }
void yyerror(const char* s)
{
   fprintf(stderr,"Parse error:%s\n",s);
   exit(1);
}
